{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 问答机器人-从问题中提取相关实体和关系\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 导入工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import ahocorasick\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 进入主目录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "os.chdir('QAMedicalKG')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "cur_dir = os.getcwd()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 载入所有特征词"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#　特征词txt文件路径\n",
    "disease_path = os.path.join(cur_dir, 'dict/disease.txt')\n",
    "department_path = os.path.join(cur_dir, 'dict/department.txt')\n",
    "check_path = os.path.join(cur_dir, 'dict/check.txt')\n",
    "drug_path = os.path.join(cur_dir, 'dict/drug.txt')\n",
    "food_path = os.path.join(cur_dir, 'dict/food.txt')\n",
    "producer_path = os.path.join(cur_dir, 'dict/producer.txt')\n",
    "symptom_path = os.path.join(cur_dir, 'dict/symptom.txt')\n",
    "deny_path = os.path.join(cur_dir, 'dict/deny.txt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载特征词\n",
    "disease_wds = [i.strip() for i in open(disease_path,encoding=\"utf-8\") if i.strip()]\n",
    "department_wds = [i.strip() for i in open(department_path,encoding=\"utf-8\") if i.strip()]\n",
    "check_wds = [i.strip() for i in open(check_path,encoding=\"utf-8\") if i.strip()]\n",
    "drug_wds = [i.strip() for i in open(drug_path,encoding=\"utf-8\") if i.strip()]\n",
    "food_wds = [i.strip() for i in open(food_path,encoding=\"utf-8\") if i.strip()]\n",
    "producer_wds = [i.strip() for i in open(producer_path,encoding=\"utf-8\") if i.strip()]\n",
    "symptom_wds = [i.strip() for i in open(symptom_path,encoding=\"utf-8\") if i.strip()]\n",
    "region_words = set(disease_wds + department_wds + check_wds + drug_wds + food_wds + producer_wds + symptom_wds)\n",
    "deny_words = [i.strip() for i in open(deny_path,encoding=\"utf-8\") if i.strip()]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 所有实体对应的类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 43430/43430 [00:19<00:00, 2280.73it/s]\n"
     ]
    }
   ],
   "source": [
    "wdtype_dict = dict()\n",
    "for word in tqdm(region_words):\n",
    "    wdtype_dict[word] = []\n",
    "    if word in disease_wds:\n",
    "        wdtype_dict[word].append('disease')\n",
    "    if word in department_wds:\n",
    "        wdtype_dict[word].append('department')\n",
    "    if word in check_wds:\n",
    "        wdtype_dict[word].append('check')\n",
    "    if word in drug_wds:\n",
    "        wdtype_dict[word].append('drug')\n",
    "    if word in food_wds:\n",
    "        wdtype_dict[word].append('food')\n",
    "    if word in symptom_wds:\n",
    "        wdtype_dict[word].append('symptom')\n",
    "    if word in producer_wds:\n",
    "        wdtype_dict[word].append('producer')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'宜昌人福复方磺胺甲噁唑片': ['producer'],\n",
       " '鱼香青豆': ['food'],\n",
       " '卡铂注射液': ['drug'],\n",
       " '拔牙后出血不止': ['symptom'],\n",
       " '吉林海外狼疮丸': ['producer'],\n",
       " '大连美罗小儿盐酸赖氨酸颗粒': ['producer'],\n",
       " '肺毛霉病': ['disease'],\n",
       " '小儿遗传性果糖不耐受': ['disease'],\n",
       " '小儿止咳糖浆': ['drug'],\n",
       " '五果冰糖羹': ['food'],\n",
       " '大同星宇星火右旋糖酐20葡': ['producer'],\n",
       " '先强药业注射用盐酸甲氯芬酯': ['producer'],\n",
       " '小儿严重急性呼吸综合征': ['disease'],\n",
       " '淋病性关节炎': ['disease'],\n",
       " '白大衣高血压': ['disease'],\n",
       " '武汉普生注射用盐酸克林霉素': ['producer'],\n",
       " '哥台': ['producer'],\n",
       " '右下腹可触及柔...': ['symptom'],\n",
       " '四川绿叶宝光利肝隆片': ['producer'],\n",
       " '协一力利鲁唑片': ['producer'],\n",
       " '卫算苏': ['producer'],\n",
       " '红烧牛肚': ['food'],\n",
       " '江西赣南海欣转移因子口服溶': ['producer'],\n",
       " '牛黄解毒丸': ['drug'],\n",
       " '溃疡分枝杆菌感染': ['disease'],\n",
       " '胺试验': ['check'],\n",
       " '胃内异物': ['disease'],\n",
       " '拔丝土豆': ['food'],\n",
       " '禾丰盐酸洛贝林注射液': ['producer'],\n",
       " '重酒石酸卡巴拉汀胶囊': ['drug'],\n",
       " '台城制药西咪替丁片': ['producer'],\n",
       " '可谱妥': ['producer'],\n",
       " '厌氧菌肺炎': ['disease'],\n",
       " '行为无计划性': ['symptom'],\n",
       " '华青红霉素眼膏': ['producer'],\n",
       " '西南药业盐酸苯海拉明注射液': ['producer'],\n",
       " '循环血浆量': ['check'],\n",
       " '吉贝尔药业醋酸甲萘氢醌片': ['producer'],\n",
       " '南京白敬宇醋酸甲萘氢醌片': ['producer'],\n",
       " '康圣堂藿香正气水': ['producer'],\n",
       " '江苏万高产妇安颗粒': ['producer'],\n",
       " '孔圣堂制药杞菊地黄丸': ['producer'],\n",
       " '奔豚气': ['disease'],\n",
       " '获得性免疫缺陷综合征视网膜病变': ['disease'],\n",
       " '慢性乳头状溃疡性脓皮病': ['disease'],\n",
       " '庆瑞金荞麦片': ['producer'],\n",
       " '四叠体受压': ['symptom'],\n",
       " '利莎林阿莫西林分散片': ['producer'],\n",
       " '碑林金嗓散结丸': ['producer'],\n",
       " '常州制药卡托普利片': ['producer'],\n",
       " '鼾症': ['disease'],\n",
       " '九旭药业盐酸布比卡因注射液': ['producer'],\n",
       " '炖猪腰': ['food'],\n",
       " '脉络膜脱离型视网膜脱离': ['disease'],\n",
       " '新生儿少吃': ['symptom'],\n",
       " '卡托普利片': ['drug'],\n",
       " '手指歪斜': ['symptom'],\n",
       " '顽固性头痛': ['symptom'],\n",
       " '盲肠阿米巴肉芽肿': ['disease', 'symptom'],\n",
       " '北京同仁堂润肌皮肤膏': ['producer'],\n",
       " '豆皮饭': ['food'],\n",
       " '蛋麦糊': ['food'],\n",
       " '婴儿睡觉不踏实': ['symptom'],\n",
       " '彼迪药业托西酸舒他西林胶囊': ['producer'],\n",
       " '腹部透视': ['check'],\n",
       " '瑞尔医药盐酸班布特罗片': ['producer'],\n",
       " '蜜汁山楂': ['food'],\n",
       " '桂林兴达硫酸锌片': ['producer'],\n",
       " '表皮全层坏死及...': ['symptom'],\n",
       " '明日制药过氧化氢溶液': ['producer'],\n",
       " '猪肉大葱蒸饺': ['food'],\n",
       " '康惠制药积雪苷霜软膏': ['producer'],\n",
       " '山东信谊硝酸甘油片': ['producer'],\n",
       " '小儿狂犬病': ['disease'],\n",
       " '蘑菇瘦肉汤': ['food'],\n",
       " '天津金耀奋乃静注射液': ['producer'],\n",
       " '坐骨神经盆腔出口狭窄症': ['disease'],\n",
       " '依静': ['producer'],\n",
       " '下腹部压痛': ['symptom'],\n",
       " '江苏恩华氯氮平片': ['producer'],\n",
       " '甘肃兰药依托泊苷注射液': ['producer'],\n",
       " '硫酸氢氯吡格雷片': ['drug'],\n",
       " '喉疾灵片': ['drug'],\n",
       " '小儿戈谢病': ['disease'],\n",
       " '肾盂内压测定': ['check'],\n",
       " '肝外胆管结石': ['symptom'],\n",
       " '康定金珠小金丸': ['producer'],\n",
       " '浅表性皮肤脂肪瘤痣': ['disease'],\n",
       " '口腔难愈的白色片状物': ['symptom'],\n",
       " '凉拌木耳菜': ['food'],\n",
       " '立庆': ['producer'],\n",
       " '信谊醋酸地塞米松片': ['producer'],\n",
       " '颈静脉检查': ['check'],\n",
       " '君碧莎消癌平片': ['producer'],\n",
       " '鲜蚕豆紫菜汤': ['food'],\n",
       " '浙江莎普爱思氟康唑滴眼液': ['producer'],\n",
       " '联环药业盐酸多西环素片': ['producer'],\n",
       " '水晶菠萝': ['food'],\n",
       " '仙琚制药克霉唑倍他米松乳膏': ['producer'],\n",
       " '心脉安片': ['drug'],\n",
       " '咽炎': ['disease'],\n",
       " '陕西京西肌苷注射液': ['producer'],\n",
       " '海参笋肉丝汤': ['food'],\n",
       " '珠蛋白生成障碍性贫血视网膜病变': ['disease'],\n",
       " '尿道口疼': ['symptom'],\n",
       " '抗胃壁细胞抗体（APCA）': ['check'],\n",
       " '芜湖张恒春香砂养胃丸': ['producer'],\n",
       " '海鲸药业维生素A软胶囊': ['producer'],\n",
       " '信谊金朱甲硫酸新斯的明注射': ['producer'],\n",
       " '人福成田药业对乙酰氨基酚栓': ['producer'],\n",
       " '东信氟康唑片': ['producer'],\n",
       " '商建磊': ['symptom'],\n",
       " '粪便中查见虫卵...': ['symptom'],\n",
       " '尺压试验': ['check'],\n",
       " '肱骨髁间骨折': ['disease'],\n",
       " '华北制药两性霉素B阴道泡腾': ['producer'],\n",
       " '高度近视': ['disease'],\n",
       " '充血性脾肿大': ['disease'],\n",
       " '恒诚制药结石通片': ['producer'],\n",
       " '促肾上腺皮质激素（ACTH）兴奋试验': ['check'],\n",
       " '胆道支架引流（ERBD）': ['check'],\n",
       " '八珍益母丸': ['drug'],\n",
       " '角膜烧伤': ['symptom'],\n",
       " '干贝': ['food'],\n",
       " '爱普森药业阿奇霉素片': ['producer'],\n",
       " '脊髓前中央动脉缺血症候群': ['disease'],\n",
       " '联环药业达那唑胶囊': ['producer'],\n",
       " '小儿七星茶颗粒': ['drug'],\n",
       " '直接胆红素与总胆红素比值': ['check'],\n",
       " '豆腐炖猪蹄': ['food'],\n",
       " 'SP': ['drug'],\n",
       " '尿黑素': ['check'],\n",
       " '毛囊瘤': ['disease'],\n",
       " 'Zieve综合征': ['disease'],\n",
       " '强酸类中毒': ['disease'],\n",
       " '渴络欣胶囊': ['drug'],\n",
       " '广西恒拓罗汉果止咳糖浆': ['producer'],\n",
       " '重庆希尔安黄柏胶囊': ['producer'],\n",
       " '反社会人格障碍(病态人格)': ['disease'],\n",
       " '眼压计测量法': ['check'],\n",
       " '先天性腹壁肌肉发育不良': ['disease'],\n",
       " '重庆药友高三尖杉酯碱注射液': ['producer'],\n",
       " '舌静脉曲张': ['disease'],\n",
       " '注射用盐酸氨溴索': ['drug'],\n",
       " '硼酸软膏': ['drug'],\n",
       " '云中山活血通脉胶囊': ['producer'],\n",
       " '脚趾痛风': ['symptom'],\n",
       " '白云峰双氯芬酸钠肠溶片': ['producer'],\n",
       " '反复发作右肺感染': ['symptom'],\n",
       " '福元药业阿昔洛韦乳膏': ['producer'],\n",
       " '颅骨透照试验': ['check'],\n",
       " '肢端肥大症性心肌病': ['disease'],\n",
       " '持续性头晕': ['symptom'],\n",
       " '足跟步行': ['symptom'],\n",
       " '缩宫素激惹试验': ['check'],\n",
       " '挤压伤': ['symptom'],\n",
       " '虫卵计数法': ['check'],\n",
       " '膝关节半月板损伤': ['disease'],\n",
       " '圣华金归洗液': ['producer'],\n",
       " '华北制药注射用硫酸链霉素': ['producer'],\n",
       " '替加氟片': ['drug'],\n",
       " '口甜': ['symptom'],\n",
       " '小儿新变异型克罗伊茨费尔特-雅各布病': ['disease'],\n",
       " '吉春制药胎宝胶囊': ['producer'],\n",
       " '皮肤科': ['department'],\n",
       " '绿豆沙': ['food'],\n",
       " '南国药业复方愈创木酚磺酸钾': ['producer'],\n",
       " '颐海药业大黄蛰虫丸': ['producer'],\n",
       " '片吸虫病': ['disease'],\n",
       " '天津和治药业集团消癌平片': ['producer'],\n",
       " '小儿慢性胃炎': ['disease'],\n",
       " '急性化脓性腱鞘炎': ['disease'],\n",
       " '白细胞介素4（iL-4）': ['check'],\n",
       " '硫酸沙丁胺醇片': ['drug'],\n",
       " '清汤全家福': ['food'],\n",
       " '四川明欣丁酸氢化可的松乳膏': ['producer'],\n",
       " '脾肾阳虚': ['symptom'],\n",
       " '黄体功能不全性不孕': ['disease'],\n",
       " '东乐制药盐酸黄酮哌酯片': ['producer'],\n",
       " '颈短': ['symptom'],\n",
       " '天津金虹胜利氧氟沙星片': ['producer'],\n",
       " '急性特发性心包炎': ['disease'],\n",
       " '信谊螺内酯片': ['producer'],\n",
       " '普华克胜双氯芬酸钠滴眼液': ['producer'],\n",
       " '迪沙药业格列吡嗪片': ['producer'],\n",
       " '华润紫竹药业扑米酮片': ['producer'],\n",
       " '国瑞琥乙红霉素片': ['producer'],\n",
       " '酿枇杷': ['food'],\n",
       " '间质性膀胱炎': ['disease'],\n",
       " '北京双鹤药业泼尼松龙片': ['producer'],\n",
       " '枸杞子炒猪肝': ['food'],\n",
       " '河北爱尔海泰盐酸纳洛酮注射': ['producer'],\n",
       " '中气不足': ['disease'],\n",
       " '跟腱断裂': ['disease'],\n",
       " '脉络膜炎': ['disease'],\n",
       " '盆腔MRI检查': ['check'],\n",
       " '肾小球滤过率下降': ['symptom'],\n",
       " 'Pancoast综合征': ['disease'],\n",
       " '间歇性跛行': ['symptom'],\n",
       " '盐酸溴己新片': ['drug'],\n",
       " '结核性苔藓': ['disease'],\n",
       " '乳头发炎': ['symptom'],\n",
       " '山西临汾盐酸苯海索片': ['producer'],\n",
       " '性施虐癖': ['symptom'],\n",
       " '海胆刺伤及海胆肉芽肿': ['disease'],\n",
       " '皮肤颌口虫病': ['disease'],\n",
       " '银朵兰维药百癣夏塔热片': ['producer'],\n",
       " '桔汁白菜': ['food'],\n",
       " '人蠕形螨病': ['disease'],\n",
       " '炒金针菇': ['food'],\n",
       " '天圣药业葡萄糖注射液': ['producer'],\n",
       " '局部麻醉药中毒': ['disease'],\n",
       " '鱼鳞病片': ['drug'],\n",
       " '九连山药业安胎丸': ['producer'],\n",
       " '单发脑梗死性痴呆': ['disease'],\n",
       " '坏死性脉管炎': ['disease'],\n",
       " '结节性硬化症': ['disease'],\n",
       " '上海中西磷酸伯氨喹片': ['producer'],\n",
       " '尿液肉眼检查': ['check'],\n",
       " '捷凝': ['producer'],\n",
       " '鳖甲炖鸽': ['food'],\n",
       " '固肠止泻丸': ['drug'],\n",
       " '泛发性红色斑块': ['symptom'],\n",
       " '盐酸金刚乙胺口服溶液': ['drug'],\n",
       " '牛黄上清片': ['drug'],\n",
       " '顽固性肥胖': ['symptom'],\n",
       " '膈肌麻痹': ['disease'],\n",
       " '依折麦布片': ['drug'],\n",
       " '注射用达卡巴嗪': ['drug'],\n",
       " '黄疸性肝炎': ['disease'],\n",
       " '琦宁复方倍氯米松樟脑乳膏': ['producer'],\n",
       " '放射过敏原吸附试验(RAST)': ['check'],\n",
       " '紫荆花药业苦参碱氯化钠注射': ['producer'],\n",
       " '小儿青盲': ['symptom'],\n",
       " '口唇发黄': ['symptom'],\n",
       " '畅维禧': ['producer'],\n",
       " '先天性膝关节脱位': ['disease'],\n",
       " '海山药业普拉洛芬滴眼液': ['producer'],\n",
       " '白扁豆粥': ['food'],\n",
       " '潜江制药葡萄糖注射液': ['producer'],\n",
       " '眼睑湿疹': ['disease'],\n",
       " '丰海复方尿囊素片': ['producer'],\n",
       " '颈部血管损伤': ['disease'],\n",
       " '岳嗣凤': ['symptom'],\n",
       " '凉拌海蜇': ['food'],\n",
       " '双颌前突': ['disease'],\n",
       " '老年人肺脓肿': ['disease'],\n",
       " '室性并行心律及室性并行心律性心动过速': ['disease'],\n",
       " '支气管舒张试验': ['check'],\n",
       " '肉末南瓜': ['food'],\n",
       " '葵花药业依托红霉素颗粒': ['producer'],\n",
       " '金泽冠心胶囊': ['drug'],\n",
       " '国药国瑞注射用克林霉素磷酸': ['producer'],\n",
       " '芹菜炒蛋': ['food'],\n",
       " '湖南康尔佳宁心宝胶囊': ['producer'],\n",
       " '华润双鹤鱼肝油酸钠注射液': ['producer'],\n",
       " '西南药业异烟肼片': ['producer'],\n",
       " '依托红霉素颗粒': ['drug'],\n",
       " '肾实质性高血压': ['disease'],\n",
       " '陕西君寿堂接骨续筋片': ['producer'],\n",
       " '白玉红油豆腐': ['food'],\n",
       " '德源药业甲钴胺胶囊': ['producer'],\n",
       " '川贝清肺糖浆': ['drug'],\n",
       " '甲沟炎和甲下脓肿': ['disease'],\n",
       " '青红萝卜猪脚蚝豉汤': ['food'],\n",
       " '运动性疲劳': ['symptom'],\n",
       " '冠状动脉异位起源': ['disease'],\n",
       " 'Ⅰ型超敏反应性疾病': ['disease'],\n",
       " '羰基镍中毒': ['disease'],\n",
       " '婴儿厌食': ['symptom'],\n",
       " '九芝堂足光散': ['producer'],\n",
       " '鲜藕素排骨': ['food'],\n",
       " '下腰部疼痛': ['symptom'],\n",
       " '麦克马瑞试验': ['check'],\n",
       " '成都第一吡喹酮片': ['producer'],\n",
       " '顽固性疼痛': ['symptom'],\n",
       " '足底脱皮': ['symptom'],\n",
       " '陕西白云灵仙跌打片': ['producer'],\n",
       " '先天性二尖瓣畸形': ['disease'],\n",
       " '前臂旋转痛': ['symptom'],\n",
       " '硝酸布康唑阴道乳膏': ['drug'],\n",
       " '硬脑膜下血肿': ['disease'],\n",
       " '鼻肿瘤': ['disease'],\n",
       " '踝部凹陷性水肿': ['symptom'],\n",
       " '手掌疤痕畸形': ['symptom'],\n",
       " '提腿试验': ['check'],\n",
       " '消炎退热颗粒': ['drug'],\n",
       " '风秘': ['disease'],\n",
       " '石药集团注射用头孢呋辛钠': ['producer'],\n",
       " '安徽东盛吡喹酮片': ['producer'],\n",
       " '小儿肺泡性蛋白沉积症': ['disease'],\n",
       " '泽兰红枣茶': ['food'],\n",
       " '妊娠合并动脉导管未闭': ['disease'],\n",
       " '胎痣': ['symptom'],\n",
       " '剥脱性皮炎': ['disease', 'symptom'],\n",
       " '尿道与阴茎结核': ['disease'],\n",
       " '丹鹿通督片': ['drug'],\n",
       " '石药集团江西金芙蓉药业甘草': ['producer'],\n",
       " '乳腺小叶增生': ['symptom'],\n",
       " '尿总氮': ['check'],\n",
       " '尿游离皮质醇(UFC)': ['check'],\n",
       " '仁济制药布洛芬片': ['producer'],\n",
       " '梅毒确诊试验': ['check'],\n",
       " '新生儿脐炎': ['disease'],\n",
       " '消脂番茄木耳豆腐汤': ['food'],\n",
       " '拌荠菜': ['food'],\n",
       " '银诺克清胰利胆颗粒': ['producer'],\n",
       " '山东威高维生素E软胶囊': ['producer'],\n",
       " '耳廓软骨膜炎': ['disease'],\n",
       " '白云山制药总厂三磷酸腺苷二': ['producer'],\n",
       " '糖醋红柿子椒': ['food'],\n",
       " '万辉双鹤四维他胶囊': ['producer'],\n",
       " '风寒感冒': ['disease'],\n",
       " '结核性肠系膜淋巴结炎': ['disease'],\n",
       " '糖醋三文鱼': ['food'],\n",
       " '脾胃舒丸': ['drug'],\n",
       " '番茄洋葱芹菜汁': ['food'],\n",
       " '海凌依': ['producer'],\n",
       " '美大康利巴韦林片': ['producer'],\n",
       " '上肢水肿': ['symptom'],\n",
       " '烯丙雌醇片': ['drug'],\n",
       " '葡萄球菌食物中毒': ['disease'],\n",
       " '外伤性脑膜炎': ['disease'],\n",
       " '百合熟地鸡蛋汤': ['food'],\n",
       " '直肠膨出': ['disease'],\n",
       " '湖南九典制药金刚藤咀嚼片': ['producer'],\n",
       " '津华晖星维生素B1片': ['producer'],\n",
       " '康惠制药宁神灵颗粒': ['producer'],\n",
       " '瘀血头痛': ['disease'],\n",
       " '五香芹菜豆': ['food'],\n",
       " '东康药业复方磺胺甲噁唑片': ['producer'],\n",
       " '天津力生制药奋乃静片': ['producer'],\n",
       " '小儿唐氏综合征': ['disease'],\n",
       " '兰药药业硬脂酸红霉素片': ['producer'],\n",
       " '益馨康麝香抗栓胶囊': ['producer'],\n",
       " '踝膝关节积液': ['symptom'],\n",
       " '山西汾河硝苯地平片': ['producer'],\n",
       " '脱水': ['disease', 'symptom'],\n",
       " '胆胃康胶囊': ['drug'],\n",
       " '热带性出汗不良': ['disease'],\n",
       " '山药桂圆炖甲鱼': ['food'],\n",
       " '单纯性寰枢椎脱位': ['disease'],\n",
       " '远大医药肾上腺色腙片': ['producer'],\n",
       " '肝窦扩张': ['symptom'],\n",
       " '指甲呈扇形': ['symptom'],\n",
       " '盐酸阿普林定片': ['drug'],\n",
       " '尿5-羟吲哚乙酸': ['check'],\n",
       " '武汉中联枸橼酸铋钾颗粒': ['producer'],\n",
       " '老年人酒精性心脏病': ['disease'],\n",
       " '国药国瑞注射用盐酸丁咯地尔': ['producer'],\n",
       " '新华制药醋酸可的松片': ['producer'],\n",
       " '腹壁血栓性静脉炎': ['disease'],\n",
       " '肩胛带肌肉萎缩': ['symptom'],\n",
       " '里急后重': ['symptom'],\n",
       " '肩胛放射性疼痛': ['symptom'],\n",
       " '河北京京过氧化氢溶液': ['producer'],\n",
       " '脉率增快': ['symptom'],\n",
       " '小儿肠系膜淋巴结结核': ['disease'],\n",
       " '枸橼酸莫沙必利分散片': ['drug'],\n",
       " '耳闷': ['symptom'],\n",
       " '山东鲁抗头孢氨苄胶囊': ['producer'],\n",
       " '复方青黛片': ['drug'],\n",
       " '人福药业注射用硝普钠': ['producer'],\n",
       " '尿黑酸': ['symptom'],\n",
       " '北京益民氯氮平片': ['producer'],\n",
       " '牛肉煎包': ['food'],\n",
       " '北京顺鑫祥云盐酸胺碘酮片': ['producer'],\n",
       " '科瑞德盐酸替扎尼定片': ['producer'],\n",
       " '香菇拌豆角': ['food'],\n",
       " '甲状腺血流显像': ['check'],\n",
       " '镇痛剂肾病': ['disease'],\n",
       " '丹毒丝菌病': ['disease'],\n",
       " '酊剂': ['drug'],\n",
       " '前列腺快感': ['symptom'],\n",
       " '盐酸奥洛他定胶囊': ['drug'],\n",
       " '注射用盐酸多西环素': ['drug'],\n",
       " '非典': ['disease'],\n",
       " '中性胰岛素注射液': ['drug', 'producer'],\n",
       " '肺和胸膜叩诊': ['check'],\n",
       " '小儿牛黄散': ['drug'],\n",
       " '新百药业注射用胸腺肽': ['producer'],\n",
       " '稽留热': ['symptom'],\n",
       " '顿呛': ['disease'],\n",
       " '鲫鱼菠菜豆腐汤': ['food'],\n",
       " '缩泉胶囊': ['drug'],\n",
       " '手套或短袜子式...': ['symptom'],\n",
       " '西安汉丰盐酸妥洛特罗片': ['producer'],\n",
       " '脉络膜缺损': ['disease'],\n",
       " '凤凰白云山药业十全大补膏': ['producer'],\n",
       " '国润制药维生素B12片': ['producer'],\n",
       " '大峻除脂生发片': ['producer'],\n",
       " '小儿先天性肾上腺皮质增生症': ['disease'],\n",
       " '石药桂利嗪片': ['producer'],\n",
       " '海王金象中药五子衍宗丸': ['producer'],\n",
       " '朝阳德远雷公藤多苷片': ['producer'],\n",
       " '云芝肝泰颗粒': ['drug'],\n",
       " '江西红星口服五维葡萄糖': ['producer'],\n",
       " '西南药业氟尿嘧啶注射液': ['producer'],\n",
       " '万邦德贞芪扶正颗粒': ['producer'],\n",
       " '口干': ['symptom'],\n",
       " '西安安健盐酸左旋咪唑片': ['producer'],\n",
       " '北京中新药业二维葡醛内酯片': ['producer'],\n",
       " '慢性附睾炎': ['disease'],\n",
       " '单纯疱疹病毒性巩膜炎': ['disease'],\n",
       " '北京中新维生素B2片': ['producer'],\n",
       " '通宣理肺丸': ['drug'],\n",
       " '虾米拌圆白菜': ['food'],\n",
       " '山东鲁抗替硝唑片': ['producer'],\n",
       " '男型骨盆': ['symptom'],\n",
       " '淀粉样变病和淀粉样关节病': ['disease'],\n",
       " '虾仁': ['food'],\n",
       " '北京同仁堂养阴清肺丸': ['producer'],\n",
       " '膀胱颈挛缩': ['disease'],\n",
       " '惠州九惠轻身消胖丸': ['producer'],\n",
       " '嗅神经检查': ['check'],\n",
       " '同德药业利多卡因氯己定气雾': ['producer'],\n",
       " '重庆希尔安蒲公英颗粒': ['producer'],\n",
       " '甲状腺功能异常伴发的精神障碍': ['disease'],\n",
       " '小儿肠旋转不良': ['disease'],\n",
       " '心阴虚': ['disease'],\n",
       " '总甲状腺素': ['check'],\n",
       " '达维邦': ['producer'],\n",
       " '抗内膜抗体阳性': ['symptom'],\n",
       " '湖南德康消癌平片': ['producer'],\n",
       " '肺蛔虫病': ['disease'],\n",
       " '跨海生化双氯芬酸钠肠溶片': ['producer'],\n",
       " '温州海鹤小儿肠胃康颗粒': ['producer'],\n",
       " '喉部堵塞感': ['symptom'],\n",
       " '太康海恩甲硝唑片': ['producer'],\n",
       " '失用步态': ['symptom'],\n",
       " '肺动脉发育不全': ['disease'],\n",
       " '中山市恒生药业银黄颗粒': ['producer'],\n",
       " '黄色肉芽肿性肾盂肾炎': ['disease'],\n",
       " '蜂窝肺': ['symptom'],\n",
       " '西南药业维生素B2注射液': ['producer'],\n",
       " '氯氮平片': ['drug'],\n",
       " '随意运动检查': ['check'],\n",
       " '哈药总厂富马酸亚铁颗粒': ['producer'],\n",
       " '北京同仁堂小儿健脾丸': ['producer'],\n",
       " '白果鸡汤': ['food'],\n",
       " '精血不足': ['symptom'],\n",
       " '清炒茼蒿菜': ['food'],\n",
       " '小儿急性肠系膜淋巴结炎': ['disease'],\n",
       " '皮蛋芦笋汤': ['food'],\n",
       " '广州白云山星群复方锌铁钙颗': ['producer'],\n",
       " '天宇奥森维生素E软胶囊': ['producer'],\n",
       " '海王福药阿苯达唑胶囊': ['producer'],\n",
       " '快乐伙伴三维制霉素栓': ['producer'],\n",
       " '科洛曲片': ['drug'],\n",
       " '抗流行性出血热IgM抗体': ['check'],\n",
       " '皇象铁力蓝天羧甲司坦片': ['producer'],\n",
       " '利群药业依托红霉素片': ['producer'],\n",
       " '端坐呼吸': ['symptom'],\n",
       " '盐酸舍曲林胶囊': ['drug'],\n",
       " '老年人病态窦房结综合征': ['disease'],\n",
       " '宛西制药归脾丸': ['producer'],\n",
       " '微丝蚴（Mf）': ['check'],\n",
       " '石家庄御生堂归脾丸': ['producer'],\n",
       " '角膜异物': ['symptom'],\n",
       " '复方鱼肝油氧化锌软膏': ['drug'],\n",
       " '血栓弹力图': ['check'],\n",
       " '正元盛邦蓼参胶囊': ['producer'],\n",
       " '百思特新血宝胶囊': ['producer'],\n",
       " '泌乳素（PRL）分泌抑制试验': ['check'],\n",
       " '抗红细胞抗体': ['check'],\n",
       " '荸荠猪肚粥': ['food'],\n",
       " '活宁': ['producer'],\n",
       " '排毒养颜胶囊': ['drug'],\n",
       " '朗致集团硫酸庆大霉素注射液': ['producer'],\n",
       " '山药羊奶羹': ['food'],\n",
       " '四川迪菲特药业胆舒软胶囊': ['producer'],\n",
       " '下肢湿性坏疽': ['symptom'],\n",
       " '诺尔玛苯磺酸氨氯地平片': ['producer'],\n",
       " '膀胱咳': ['disease'],\n",
       " '肺泡蛋白沉着症': ['disease'],\n",
       " '上海华源苯丙氨酯片': ['producer'],\n",
       " '远程制药抗妇炎胶囊': ['producer'],\n",
       " '亚急性坏死性脊髓炎': ['disease'],\n",
       " '退变性关节病': ['disease'],\n",
       " '黄石奇灵麝香壮骨膏': ['producer'],\n",
       " '眼眶静脉性血管瘤': ['disease'],\n",
       " '颈椎单侧及双侧小关节脱位': ['disease'],\n",
       " '豹纹状眼底': ['symptom'],\n",
       " '腋毛毛干上有微小结节': ['symptom'],\n",
       " '甲磺酸阿米三嗪萝巴新片': ['drug', 'producer'],\n",
       " '尿素': ['check'],\n",
       " '武汉钧安酮洛芬肠溶胶囊': ['producer'],\n",
       " '安国药业生发丸': ['producer'],\n",
       " '唐山利康尿素维E乳膏': ['producer'],\n",
       " '脑电波的改变': ['symptom'],\n",
       " '保定金钟疤痕止痒软化膏': ['producer'],\n",
       " '威海华新强力碘溶液': ['producer'],\n",
       " '云南白药健胃消食片': ['producer'],\n",
       " '部分凝血活酶时间': ['check'],\n",
       " '爱络': ['producer'],\n",
       " '川大华西醋酸甲萘氢醌片': ['producer'],\n",
       " '包头中药鼻炎宁颗粒': ['producer'],\n",
       " '血清无机磷': ['check'],\n",
       " '京舒阿托伐他汀钙分散片': ['producer'],\n",
       " '欣苗琥乙红霉素颗粒': ['producer'],\n",
       " '宁兰欣': ['producer'],\n",
       " '威尔曼制药注射用头孢呋辛钠': ['producer'],\n",
       " '顺铂注射液': ['drug', 'producer'],\n",
       " '金胃泰胶囊': ['drug'],\n",
       " '虚寒体质': ['symptom'],\n",
       " '苹果酱': ['food'],\n",
       " '江苏振国依托泊苷注射液': ['producer'],\n",
       " '科田药业环吡酮胺乳膏': ['producer'],\n",
       " '纤维蛋白肽Bβ15～42': ['check'],\n",
       " '博恩特药业注射用醋酸亮丙瑞': ['producer'],\n",
       " '葱油苦瓜': ['food'],\n",
       " '活血首乌参': ['food'],\n",
       " '香菇粥': ['food'],\n",
       " '鼻子颜色苍白': ['symptom'],\n",
       " '肠外结核': ['symptom'],\n",
       " '万生力乐盐酸帕罗西汀片': ['producer'],\n",
       " '上海新亚复方磺胺甲噁唑片': ['producer'],\n",
       " '碑林药业金嗓散结片': ['producer'],\n",
       " '天泰降糖舒片': ['producer'],\n",
       " '普元除湿止痒洗液': ['producer'],\n",
       " '金砂五淋丸': ['drug'],\n",
       " '体位性震颤': ['symptom'],\n",
       " '皮肤弹性检查': ['check'],\n",
       " '复方吡拉西坦脑蛋白水解物片': ['drug'],\n",
       " '回音必孕康口服液': ['producer'],\n",
       " '浙江普洛康川贝清肺糖浆': ['producer'],\n",
       " '偏振光显微镜检查': ['check'],\n",
       " '宫颈糜烂': ['disease'],\n",
       " '老年女性膀胱颈梗阻': ['disease'],\n",
       " '陕西诚信盐酸妥洛特罗片': ['producer'],\n",
       " '杞子南枣煲鸡蛋': ['food'],\n",
       " '拇指不明原因疼痛': ['symptom'],\n",
       " '无名指半月甲呈粉红色': ['symptom'],\n",
       " '哈密瓜百合汤': ['food'],\n",
       " '凉拌四季豆': ['food'],\n",
       " '病毒性心肌炎': ['disease'],\n",
       " '翠衣番茄豆腐汤': ['food'],\n",
       " '百利金转移因子口服溶液': ['producer'],\n",
       " '椰子饺': ['food'],\n",
       " '眉下垂或位置低': ['symptom'],\n",
       " '淋菌性结膜炎': ['disease'],\n",
       " '固肾安胎丸': ['drug'],\n",
       " '湖北绿金子胃膜素胶囊': ['producer'],\n",
       " '麻仁鸽蛋': ['food'],\n",
       " '成都蓉生人血白蛋白': ['producer'],\n",
       " '鱼香鸡爪': ['food'],\n",
       " '周期性内斜视': ['disease'],\n",
       " '水母皮炎': ['disease'],\n",
       " '妇炎康软胶囊': ['drug'],\n",
       " '脐周肿胀': ['symptom'],\n",
       " '眼压突然迅速升高': ['symptom'],\n",
       " '瑞奥奥美拉唑肠溶片': ['producer'],\n",
       " '舌咬伤': ['symptom'],\n",
       " '海参蒸饺': ['food'],\n",
       " '复方谷氨酰胺肠溶胶囊': ['drug'],\n",
       " '芒果拼盘': ['food'],\n",
       " '尿频伴尿急和尿痛': ['symptom'],\n",
       " '脂蛋白a（Lp-a）': ['check'],\n",
       " '尿道结节': ['symptom'],\n",
       " '麦芽糖': ['food'],\n",
       " '舒视明氨碘肽滴眼液': ['producer'],\n",
       " '鲫鱼粥': ['food'],\n",
       " '颌下间隙感染': ['disease'],\n",
       " '克痒敏醑': ['drug'],\n",
       " '脱肛': ['symptom'],\n",
       " '麦芙欣': ['producer'],\n",
       " '电脑失写症': ['symptom'],\n",
       " '海口奇力注射用阿洛西林钠': ['producer'],\n",
       " '遂成药业葡萄糖注射液': ['producer'],\n",
       " '盐酸二甲双胍片': ['drug'],\n",
       " '淋巴细胞性垂体炎': ['disease'],\n",
       " '浙江维康固元胶囊': ['producer'],\n",
       " '乙肝表面抗体（...': ['symptom'],\n",
       " '不典型增生': ['symptom'],\n",
       " '火腿海参木耳排骨汤': ['food'],\n",
       " '百合鸡蛋黄汤': ['food'],\n",
       " '芝麻黑豆粥': ['food'],\n",
       " '新安药业盐酸吗啉胍片': ['producer'],\n",
       " '香脆银鱼': ['food'],\n",
       " '盐酸吗啉胍滴眼液': ['drug'],\n",
       " '信谊天平炔诺酮片': ['producer'],\n",
       " '胚胎发育供血不足': ['symptom'],\n",
       " '鼻咽部MRI检查': ['check'],\n",
       " '肝苏软胶囊': ['drug'],\n",
       " '河南神农药业清开灵注射液': ['producer'],\n",
       " '河北健宁碘酊': ['producer'],\n",
       " '顽固性心功能不全': ['symptom'],\n",
       " '息贲': ['disease'],\n",
       " '陕西渭南华仁藻酸双酯钠片': ['producer'],\n",
       " '荸荠鸡翅': ['food'],\n",
       " '珊瑚癣净': ['drug'],\n",
       " '恶心与呕吐': ['symptom'],\n",
       " '肌张力过高': ['symptom'],\n",
       " '北京同仁堂芎菊上清丸': ['producer'],\n",
       " '艾瑞得安': ['producer'],\n",
       " '山西云鹏维生素B2片': ['producer'],\n",
       " '美德止血祛瘀明目片': ['producer'],\n",
       " '特异性心肌病': ['disease'],\n",
       " '贵州安康制药安胎丸': ['producer'],\n",
       " '三明天泰硫软膏': ['producer'],\n",
       " '乳房或乳头未发育': ['symptom'],\n",
       " '羊水栓塞': ['disease'],\n",
       " '中度精神发育迟滞': ['symptom'],\n",
       " '菊花鲈鱼块': ['food'],\n",
       " '恶性高血压视网膜病变': ['disease'],\n",
       " '卵泡囊肿': ['disease', 'symptom'],\n",
       " '合肥利民制药氧氟沙星滴眼液': ['producer'],\n",
       " '维生素K1注射液': ['drug', 'producer'],\n",
       " '尿蛋白': ['symptom'],\n",
       " '达力新': ['producer'],\n",
       " '气臌': ['disease'],\n",
       " '巨幼细胞性贫血': ['disease'],\n",
       " '丛状血管瘤': ['disease'],\n",
       " '小儿止泻灵颗粒': ['drug'],\n",
       " '银鱼火锅': ['food'],\n",
       " '锦华药业氯霉素片': ['producer'],\n",
       " '苍耳子辛夷花芥菜汤': ['food'],\n",
       " '广西灵峰妇康宁片': ['producer'],\n",
       " '四川并殖吸虫病': ['disease'],\n",
       " '红细胞膜磷脂': ['check'],\n",
       " '山东明仁福瑞达盐酸硫必利片': ['producer'],\n",
       " '循环免疫复合物': ['check'],\n",
       " '通化兴华苯妥英钠片': ['producer'],\n",
       " '山东威高葡萄糖氯化钠注射液': ['producer'],\n",
       " '生长激素分泌过少': ['symptom'],\n",
       " '胆舒软胶囊': ['drug'],\n",
       " '胫骨粗隆肿胀': ['symptom'],\n",
       " '四川大冢谷维素片': ['producer'],\n",
       " '足菌肿': ['disease'],\n",
       " '苦瓜豆浆汁': ['food'],\n",
       " '999茵栀黄口服液': ['producer'],\n",
       " '角膜知觉减少': ['symptom'],\n",
       " '淋巴结疼痛': ['symptom'],\n",
       " '乐普药业司帕沙星片': ['producer'],\n",
       " '西岳制药托西酸舒他西林胶囊': ['producer'],\n",
       " '奇比特': ['producer'],\n",
       " '天泰药业止痛化癥胶囊': ['producer'],\n",
       " '长圣药业乌洛托品溶液': ['producer'],\n",
       " '芪枣颗粒': ['drug'],\n",
       " '泰素': ['producer'],\n",
       " '外阴烧灼刺激感': ['symptom'],\n",
       " '广西冠峰陈香露白露片': ['producer'],\n",
       " '萝卜干饺': ['food'],\n",
       " '无效腔气量／潮气量比值': ['check'],\n",
       " '肠炎宁片': ['drug'],\n",
       " '赛克同': ['producer'],\n",
       " '三高症': ['disease'],\n",
       " '恶性黑色素瘤': ['disease'],\n",
       " '天圣制药舒肝和胃丸': ['producer'],\n",
       " '菠菜拌豆干': ['food'],\n",
       " '钧安制药葡萄糖酸锌片': ['producer'],\n",
       " '华润双鹤药业醋酸甲萘氢醌片': ['producer'],\n",
       " '足底和足背浮肿': ['symptom'],\n",
       " '流行性出血热病毒抗体': ['check'],\n",
       " '内分泌性高血压': ['disease'],\n",
       " '胆胀': ['disease'],\n",
       " '枸杞子乌肉鸡汤': ['food'],\n",
       " '江苏鹏鹞马来酸氯苯那敏片': ['producer'],\n",
       " '黄栀花药业血府逐瘀丸': ['producer'],\n",
       " '国药集团武汉中联四药药业三': ['producer'],\n",
       " '小儿波-杰综合征': ['disease'],\n",
       " '尿道的条索状肿块': ['symptom'],\n",
       " '灯盏花素片': ['drug'],\n",
       " '蒜茸野菊花': ['food'],\n",
       " '卵磷脂片': ['drug'],\n",
       " '硝苯地平片': ['drug'],\n",
       " '牙齿缝隙大': ['symptom'],\n",
       " '吉祥药业盐酸海索那林片': ['producer'],\n",
       " '难产': ['disease'],\n",
       " '太极集团复方鱼腥草片': ['producer'],\n",
       " '华意甲硝唑片': ['producer'],\n",
       " '胎心不规则': ['symptom'],\n",
       " '鲁平盐酸胺碘酮片': ['producer'],\n",
       " '右室肥厚': ['symptom'],\n",
       " '东维力': ['producer'],\n",
       " '广东博洲药业头孢特仑新戊酯': ['producer'],\n",
       " '路德药业小儿肺炎散': ['producer'],\n",
       " '山药炒鱼片': ['food'],\n",
       " '江西科伦托吡卡胺滴眼液': ['producer'],\n",
       " '眉豆煲猪胰汤': ['food'],\n",
       " '广东逢春补中益气丸': ['producer'],\n",
       " '巴特日七味丸': ['drug'],\n",
       " '吉林华港制药盐酸二氧丙嗪颗': ['producer'],\n",
       " '米非司酮胶囊': ['drug'],\n",
       " '炝泥胡菜': ['food'],\n",
       " '东药硝苯地平片': ['producer'],\n",
       " '洛正筋骨痛消丸': ['producer'],\n",
       " '遂成药业替硝唑胶囊': ['producer'],\n",
       " '布美他尼注射液': ['drug'],\n",
       " '咽喉干燥及灼热感': ['symptom'],\n",
       " '齐都药业尼麦角林片': ['producer'],\n",
       " '肾脓肿': ['disease', 'symptom'],\n",
       " '小儿维生素D缺乏性手足搐搦症': ['disease'],\n",
       " '早产视网膜病变筛查': ['check'],\n",
       " '尿羟脯氨酸': ['check'],\n",
       " '青春期肥胖': ['symptom'],\n",
       " '海王福药溴丙胺太林片': ['producer'],\n",
       " '复发性多软骨炎': ['disease'],\n",
       " '河北长天果糖二磷酸钙片': ['producer'],\n",
       " '中间细胞(MID)': ['check'],\n",
       " '云药盐酸可乐定片': ['producer'],\n",
       " '吉通药业冠脉宁片': ['producer'],\n",
       " '南建广': ['symptom'],\n",
       " '西瓜番茄汁': ['food'],\n",
       " '自恋': ['symptom'],\n",
       " '巴红': ['producer'],\n",
       " '上海黄海制药氯化钾缓释片': ['producer'],\n",
       " '嘉通芪芳气血颗粒': ['producer'],\n",
       " '小儿原发性免疫缺陷病': ['disease'],\n",
       " '当归首乌鸡肉汤': ['food'],\n",
       " '骨血管内皮细胞瘤': ['disease'],\n",
       " '敖东延吉贞芪扶正颗粒': ['producer'],\n",
       " '烩鸡翅': ['food'],\n",
       " '小儿无菌性脑膜炎综合征': ['disease'],\n",
       " '胸部滴水声': ['check'],\n",
       " '眉间皱纹': ['symptom'],\n",
       " '羊肉炖柿子': ['food'],\n",
       " '华润双鹤药业核黄素磷酸钠注': ['producer'],\n",
       " '奥邦甘露聚糖肽口服溶液': ['producer'],\n",
       " '翔通药业硼酸软膏': ['producer'],\n",
       " '西安方兴谷丙甘氨酸胶囊': ['producer'],\n",
       " '恒健新霉素氟轻松乳膏': ['producer'],\n",
       " '药都制药跌打丸': ['producer'],\n",
       " '永寿制药消癌平片': ['producer'],\n",
       " '哈尔滨凯程人工牛黄甲硝唑胶': ['producer'],\n",
       " '惠松硅炭银片': ['producer'],\n",
       " '糖尿病肾病': ['disease'],\n",
       " '脑脊液生长抑素': ['check'],\n",
       " '胎膜早破': ['disease', 'symptom'],\n",
       " '晨骨刺宁片': ['producer'],\n",
       " '特发性嗜酸性粒细胞增多综合征': ['disease'],\n",
       " '富马酸依美斯汀滴眼液': ['drug'],\n",
       " '吉林华港制药头孢羟氨苄甲氧': ['producer'],\n",
       " '康人痔速宁片': ['producer'],\n",
       " '间质性肺炎': ['disease'],\n",
       " '石药唐威补肾强身片': ['producer'],\n",
       " '瞳孔中能见到白色反光': ['symptom'],\n",
       " '间接免疫荧光试验': ['check'],\n",
       " '小儿急性中毒性脑病': ['disease'],\n",
       " '神经伤': ['symptom'],\n",
       " '第一生化胰岛素注射液': ['producer'],\n",
       " '精子稀少': ['symptom'],\n",
       " '活力源片': ['drug'],\n",
       " '仙河药业妇炎舒片': ['producer'],\n",
       " '白云山明兴盐酸肾上腺素注射': ['producer'],\n",
       " '天宏药业苯扎贝特片': ['producer'],\n",
       " '小儿硬皮病': ['disease'],\n",
       " '豆浆': ['food'],\n",
       " '偻附': ['disease'],\n",
       " '辽宁金丹加味逍遥丸': ['producer'],\n",
       " '地道药业独一味软胶囊': ['producer'],\n",
       " '悦康普欣阿德福韦酯片': ['producer'],\n",
       " '硝酸咪康唑乳膏': ['drug'],\n",
       " '洛各单酒石酸罗格列酮片': ['producer'],\n",
       " '全宇制药西咪替丁片': ['producer'],\n",
       " '圣鲁制药环磷腺苷葡胺注射液': ['producer'],\n",
       " '帅孚': ['producer'],\n",
       " '金岛制药磺胺嘧啶片': ['producer'],\n",
       " '肾外梗阻': ['symptom'],\n",
       " '迪康长江制药盐酸肾上腺素注': ['producer'],\n",
       " '肝上皮样血管内皮细胞瘤': ['disease'],\n",
       " '同仁堂八味锡类散': ['producer'],\n",
       " '北京中新药业甲巯咪唑片': ['producer'],\n",
       " '形美复方珍珠暗疮胶囊': ['producer'],\n",
       " '鲁抗大地药业排毒清脂胶囊': ['producer'],\n",
       " '咖喱牛肉蒸饺': ['food'],\n",
       " '康普药业盐酸左氧氟沙星胶囊': ['producer'],\n",
       " '四边孔处的局限压痛': ['symptom'],\n",
       " '合肥久联己烯雌酚片': ['producer'],\n",
       " '氨碘肽滴眼液': ['drug'],\n",
       " '甘蔗萝卜汤': ['food'],\n",
       " '赤豆牛肉汤': ['food'],\n",
       " '复达欣': ['producer'],\n",
       " '廖元和堂生精胶囊': ['producer'],\n",
       " '急性腹泻': ['disease'],\n",
       " '双鲸药业维生素A软胶囊': ['producer'],\n",
       " '武汉中联三维制霉素栓': ['producer'],\n",
       " '酸碱灼伤': ['disease'],\n",
       " '豆腐鸡血瘦肉汤': ['food'],\n",
       " '通辽东北六复方磺胺甲噁唑片': ['producer'],\n",
       " '职业性痤疮': ['disease'],\n",
       " '上海上药信谊药厂乙酰唑胺片': ['producer'],\n",
       " '奥托康制药硫唑嘌呤片': ['producer'],\n",
       " '亚邦强生药业吡喹酮片': ['producer'],\n",
       " '茯苓清蒸桂鱼': ['food'],\n",
       " '云南傣药维生素B2注射液': ['producer'],\n",
       " '闭塞性血栓性脉管炎': ['disease'],\n",
       " '惠氏制药公司西罗莫司片': ['producer'],\n",
       " '时珍康氧化锌软膏': ['producer'],\n",
       " '肺力咳胶囊': ['drug'],\n",
       " '主动脉夹层': ['disease'],\n",
       " '九洋药业卡马西平胶囊': ['producer'],\n",
       " '月经期长痘': ['symptom'],\n",
       " '骨刺宁片': ['drug'],\n",
       " '亚宝药业曲克芦丁片': ['producer'],\n",
       " '胡庆余堂胃复春片': ['producer'],\n",
       " '临汾健民复合维生素B片': ['producer'],\n",
       " '气性坏疽': ['disease'],\n",
       " '维宏': ['producer'],\n",
       " '水萝卜片汤': ['food'],\n",
       " '疝气': ['disease'],\n",
       " '泪膜破裂时间': ['check'],\n",
       " '汕头金石枸橼酸铋钾颗粒': ['producer'],\n",
       " '广东罗浮山白鹤消炎利胆片': ['producer'],\n",
       " '山西振东诺氟沙星胶囊': ['producer'],\n",
       " '臂痛': ['symptom'],\n",
       " '浙江万晟硝苯地平片': ['producer'],\n",
       " '损伤性休克': ['disease'],\n",
       " '睾丸疼痛': ['symptom'],\n",
       " '红烧鳝鱼': ['food'],\n",
       " '天朗制药盐酸洛美沙星滴眼液': ['producer'],\n",
       " '生精片': ['drug'],\n",
       " '十二指肠憩室': ['disease'],\n",
       " '肛门短时间阵发性钝痛': ['symptom'],\n",
       " '帽状腱膜下脓肿': ['disease'],\n",
       " '耳丝拌凉粉': ['food'],\n",
       " '腹水': ['disease', 'symptom'],\n",
       " '肝包虫囊肿': ['disease'],\n",
       " '干眼': ['disease'],\n",
       " '藻酸双酯钠片': ['drug'],\n",
       " '带状疱疹性角膜炎': ['disease'],\n",
       " '脑动脉盗血综合征': ['disease'],\n",
       " '放射性心脏损害': ['disease'],\n",
       " '格林生物硬脂酸红霉素片': ['producer'],\n",
       " '集佳调经促孕丸': ['producer'],\n",
       " '粪柱变形变细': ['symptom'],\n",
       " '河南羚锐制药盐酸克林霉素胶': ['producer'],\n",
       " '智力减低': ['symptom'],\n",
       " '静脉注射肾盂摄影检查': ['check'],\n",
       " '头孢克肟胶囊': ['drug'],\n",
       " '炭疽': ['disease'],\n",
       " '莱阳司邦得制药盐酸金刚烷胺': ['producer'],\n",
       " '誉隆亚东药业接骨续筋片': ['producer'],\n",
       " '尿道炎': ['disease'],\n",
       " '青岛双鲸维生素E软胶囊': ['producer'],\n",
       " '通化茂祥司莫司汀胶囊': ['producer'],\n",
       " '云片银耳汤': ['food'],\n",
       " '黑龙江金九维生素E皇浆口服': ['producer'],\n",
       " '湖北华世通潜龙注射用单磷酸': ['producer'],\n",
       " '陕西京西维生素B6注射液': ['producer'],\n",
       " '牙齿异常': ['symptom'],\n",
       " '乐普药业注射用头孢他啶': ['producer'],\n",
       " '牛肚粥': ['food'],\n",
       " '瘦肉燕窝汤': ['food'],\n",
       " '钼': ['check'],\n",
       " '鲫鱼': ['food'],\n",
       " '汇莱药业保和丸': ['producer'],\n",
       " '睡眠呼吸暂停综合征': ['disease'],\n",
       " '成都药业四环素片': ['producer'],\n",
       " '利民制药盐酸左氧氟沙星注射': ['producer'],\n",
       " '山东鲁抗硫酸锌片': ['producer'],\n",
       " '创灼膏': ['drug'],\n",
       " '仁盛制药参芪首乌补汁': ['producer'],\n",
       " '阿利新蓝染色': ['check'],\n",
       " '华润双鹤氨甲环酸片': ['producer'],\n",
       " '泰华堂祛风止痒口服液': ['producer'],\n",
       " '湖北康沁膦甲酸钠氯化钠注射': ['producer'],\n",
       " '颈椎分节异常': ['symptom'],\n",
       " '红细胞增多症眼底': ['disease'],\n",
       " '维必朗氯氮平口腔崩解片': ['producer'],\n",
       " '注射用硫酸长春新碱': ['drug', 'producer'],\n",
       " '致死性家族性失眠症': ['disease'],\n",
       " '5＇-核苷酸酶': ['check'],\n",
       " '黑龙江诺捷制药乳酸菌素片': ['producer'],\n",
       " '精神障碍': ['disease', 'symptom'],\n",
       " '幻味': ['symptom'],\n",
       " '良性脑瘤': ['disease'],\n",
       " '白敬宇制药奋乃静片': ['producer'],\n",
       " '浙江巨泰灭菌结晶磺胺': ['producer'],\n",
       " '上海新亚注射用丝裂霉素': ['producer'],\n",
       " '代树芳': ['symptom'],\n",
       " '掌骨指数及指骨...': ['symptom'],\n",
       " '天原药业利肝隆片': ['producer'],\n",
       " '老年人急性淋巴细胞白血病': ['disease'],\n",
       " '腹壁间疝': ['disease'],\n",
       " '小儿金葡菌性烫伤样皮肤综合征': ['disease'],\n",
       " '黄河药业熊去氧胆酸片': ['producer'],\n",
       " '玫卢玫芦消痤膏': ['producer'],\n",
       " '应激性溃疡': ['disease'],\n",
       " '奶汁白菜条': ['food'],\n",
       " '手部血管损伤': ['disease'],\n",
       " '正大天晴泽桂癃爽胶囊': ['producer'],\n",
       " '肺热咳嗽': ['disease'],\n",
       " '紫菜豆腐羹': ['food'],\n",
       " '吉林长源辛芳鼻炎胶囊': ['producer'],\n",
       " '江苏吴中苏州制药西洛他唑片': ['producer'],\n",
       " '双耳汤': ['food'],\n",
       " '源瑞制药聚甲酚磺醛栓': ['producer'],\n",
       " '新疆华世丹维生素E胶丸': ['producer'],\n",
       " '九惠制药毛冬青胶囊': ['producer'],\n",
       " '吉林恒和维康枸橼酸钾颗粒': ['producer'],\n",
       " '重复膀胱': ['disease'],\n",
       " '今方药业散结片': ['producer'],\n",
       " '苏中药业甘露聚糖肽注射液': ['producer'],\n",
       " '江西药都樟树木香顺气丸': ['producer'],\n",
       " '分水岭区脑梗死': ['disease'],\n",
       " '仙河药业刺五加脑灵胶囊': ['producer'],\n",
       " '仁和堂五氟利多片': ['producer'],\n",
       " '外科检查': ['check'],\n",
       " '陕西华龙制药轻身减肥片': ['producer'],\n",
       " '喉外伤': ['disease'],\n",
       " '克拉霉素分散片': ['drug', 'producer'],\n",
       " '注射用头孢呋辛钠': ['drug', 'producer'],\n",
       " '大连华立金港三磷酸腺苷二钠': ['producer'],\n",
       " '结肠血管畸形': ['disease'],\n",
       " '大白菜饺': ['food'],\n",
       " '海力制药盐酸左氧氟沙星片': ['producer'],\n",
       " '脉络膜凹陷': ['symptom'],\n",
       " '毛母质瘤': ['disease'],\n",
       " '并指(趾)畸形检查': ['check'],\n",
       " '沈阳东新宁心宝胶囊': ['producer'],\n",
       " '看东西有重影': ['symptom'],\n",
       " '肢体不自主震颤': ['symptom'],\n",
       " '陕西盘龙康尔心胶囊': ['producer'],\n",
       " '威凡': ['producer'],\n",
       " '补体结合试验': ['check'],\n",
       " '皇象铁力蓝天维生素E烟酸酯': ['producer'],\n",
       " '牙龈炎': ['disease'],\n",
       " '明水药业注射用头孢唑林钠': ['producer'],\n",
       " '皮肤病': ['disease'],\n",
       " '妊娠期急性肾功能衰竭': ['disease'],\n",
       " '枸橼酸莫沙必利片': ['drug'],\n",
       " '安徽万森维D2磷酸氢钙片': ['producer'],\n",
       " '蒲地蓝消炎口服液': ['drug', 'producer'],\n",
       " '金陵南京金陵脉络宁口服液': ['producer'],\n",
       " '华北制药注射用青霉素钠': ['producer'],\n",
       " '茴香': ['food'],\n",
       " '一过性心尖部收...': ['symptom'],\n",
       " '兴隆希力丹参酮胶囊': ['producer'],\n",
       " '正大丰海盐酸多西环素片': ['producer'],\n",
       " '顽固性呃逆': ['symptom'],\n",
       " '钩虫皮炎': ['disease'],\n",
       " '安生新霉素氟轻松乳膏': ['producer'],\n",
       " '脊椎结核后突畸形': ['disease'],\n",
       " '肺病': ['disease'],\n",
       " '大株红景天片': ['drug'],\n",
       " '柠檬鹌鹑': ['food'],\n",
       " '广州白云山天心酒石酸美托洛': ['producer'],\n",
       " '小儿丘疹性肢皮炎综合征': ['disease'],\n",
       " '仁和堂药业吡拉西坦片': ['producer'],\n",
       " '午夜一片法地塞米松抑制试验': ['check'],\n",
       " '四川远大蜀阳人血白蛋白': ['producer'],\n",
       " '浙江亚东制药阿莫西林胶囊': ['producer'],\n",
       " '老年人多器官功能衰竭': ['disease'],\n",
       " '苏州壹药注射用盐酸氨溴索': ['producer'],\n",
       " '足畸形': ['symptom'],\n",
       " '海绵体血管瘤': ['disease'],\n",
       " '盐酸布比卡因注射液': ['drug'],\n",
       " '小米面发糕': ['food'],\n",
       " '芋头煮肉丸': ['food'],\n",
       " '遂成药业红霉素软膏': ['producer'],\n",
       " '胸、腰椎椎体单纯性、楔形压缩骨折': ['disease'],\n",
       " '咳嗽': ['disease', 'symptom'],\n",
       " '康必得药业复方醋酸氯己定喷': ['producer'],\n",
       " '贵州汉方依托泊苷注射液': ['producer'],\n",
       " '钒': ['check'],\n",
       " '天津中新健步壮骨丸': ['producer'],\n",
       " '立业制药诺氟沙星滴眼液': ['producer'],\n",
       " '苄达赖氨酸滴眼液': ['drug'],\n",
       " '正瑞': ['producer'],\n",
       " '颈部潮红': ['symptom'],\n",
       " '成都锦华吡嗪酰胺片': ['producer'],\n",
       " '两眼上视障碍': ['symptom'],\n",
       " '天津太平洋丙酸倍氯米松乳膏': ['producer'],\n",
       " '骨刺丸': ['drug'],\n",
       " '砂仁甘草蒸鲫鱼': ['food'],\n",
       " '胸主动脉瘤': ['disease'],\n",
       " '腰部酸胀及无力': ['symptom'],\n",
       " '白塞综合征': ['disease'],\n",
       " '北京益民药业盐酸氯丙嗪片': ['producer'],\n",
       " '小儿爱德华兹综合征': ['disease'],\n",
       " '溃平宁颗粒': ['drug'],\n",
       " '猪肉炒山楂': ['food'],\n",
       " '牡丹江灵泰藻酸双酯钠片': ['producer'],\n",
       " '江苏九旭鸦胆子油乳注射液': ['producer'],\n",
       " '山东方明酒石酸美托洛尔注射': ['producer'],\n",
       " '安神补脑液': ['drug'],\n",
       " '心理性性功能障碍': ['symptom'],\n",
       " '江苏神华宁心宝胶囊': ['producer'],\n",
       " '白果（鲜）': ['food'],\n",
       " '阴道炎': ['disease'],\n",
       " '抗淋巴细胞抗体（ALA）': ['check'],\n",
       " '成都湔江积雪苷片': ['producer'],\n",
       " '结肠黑变': ['symptom'],\n",
       " '吉春止痒消炎水': ['producer'],\n",
       " '易亨制药双氯芬酸钠缓释胶囊': ['producer'],\n",
       " '依科制药石淋通颗粒': ['producer'],\n",
       " '石药欧意尼群地平片': ['producer'],\n",
       " '陕西关爱甲硝唑氯己定洗剂': ['producer'],\n",
       " '乐家老铺参梅养胃颗粒': ['producer'],\n",
       " '辅仁药业盐酸多沙普仑注射液': ['producer'],\n",
       " '未分化脊柱关节病': ['disease'],\n",
       " '蘑菇炒芦笋': ['food'],\n",
       " '妊娠期胸痛': ['symptom'],\n",
       " '上海信谊氧氟沙星滴耳液': ['producer'],\n",
       " '黑豆': ['food'],\n",
       " '星鲨制药颠茄片': ['producer'],\n",
       " '肺泡癌': ['disease'],\n",
       " '乐仁堂茴香橘核丸': ['producer'],\n",
       " '注射用哌拉西林钠他唑巴坦钠': ['drug'],\n",
       " ...}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wdtype_dict"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 构造AC自动机，加速实体提取"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当知识图谱规模过大时，使用AC自动机算法，从问题中提取知识图谱中的实体，而不是用原生python的字符串方法。\n",
    "\n",
    "扩展阅读：https://zhuanlan.zhihu.com/p/158767004"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''构造AC自动机，加速过滤'''\n",
    "def build_actree(wordlist):\n",
    "    actree = ahocorasick.Automaton()\n",
    "    for index, word in enumerate(wordlist):\n",
    "        actree.add_word(word, (index, word))\n",
    "    actree.make_automaton()\n",
    "    return actree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构造AC自动机\n",
    "region_tree = build_actree(list(region_words))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<ahocorasick.Automaton at 0x7f900bcf59d0>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "region_tree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'血常规' in region_tree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(12026, '血常规')"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "region_tree.get('血常规')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'学习' in region_tree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mKeyError\u001B[0m                                  Traceback (most recent call last)",
      "\u001B[0;32m<ipython-input-16-8c23f2dd3e0c>\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[0;32m----> 1\u001B[0;31m \u001B[0mregion_tree\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mget\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m'学习'\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m",
      "\u001B[0;31mKeyError\u001B[0m: "
     ]
    }
   ],
   "source": [
    "region_tree.get('学习')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 任务一：提取问题相关实体及其类别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "question = '肺气肿和百日咳要做血常规吗'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, (16220, '肺气肿'))\n",
      "(6, (21279, '百日咳'))\n",
      "(11, (12026, '血常规'))\n",
      "['肺气肿', '百日咳', '血常规']\n"
     ]
    }
   ],
   "source": [
    "question_entity = []\n",
    "for each in region_tree.iter(question):\n",
    "    print(each)\n",
    "    entity = each[1][1]\n",
    "    question_entity.append(entity)\n",
    "print(question_entity)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "# stop_wds = []\n",
    "# # 排除字符串子串\n",
    "# for wd1 in region_wds:\n",
    "#     for wd2 in region_wds:\n",
    "#         if wd1 in wd2 and wd1 != wd2:\n",
    "#             stop_wds.append(wd1)\n",
    "# print(stop_wds)\n",
    "# final_wds = [each for each in region_wds if each not in stop_wds]\n",
    "# final_wds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "question_entity_dict = {each:wdtype_dict[each] for each in question_entity}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'肺气肿': ['disease'], '百日咳': ['disease'], '血常规': ['check']}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "question_entity_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "output = {}\n",
    "output['args'] = question_entity_dict"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 任务一完成"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 任务二：提取问题相关的待查询关系"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 问题中涉及的实体类别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "types = []\n",
    "for each in question_entity_dict.values():\n",
    "    types.extend(each)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['disease', 'disease', 'check']"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "types"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 不同提问意图的疑问词"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "symptom_qwds = ['症状', '表征', '现象', '症候', '表现']\n",
    "cause_qwds = ['原因','成因', '为什么', '怎么会', '怎样才', '咋样才', '怎样会', '如何会', '为啥', '为何', '如何才会', '怎么才会', '会导致', '会造成']\n",
    "acompany_qwds = ['并发症', '并发', '一起发生', '一并发生', '一起出现', '一并出现', '一同发生', '一同出现', '伴随发生', '伴随', '共现']\n",
    "food_qwds = ['饮食', '饮用', '吃', '食', '伙食', '膳食', '喝', '菜' ,'忌口', '补品', '保健品', '食谱', '菜谱', '食用', '食物','补品']\n",
    "drug_qwds = ['药', '药品', '用药', '胶囊', '口服液', '炎片']\n",
    "prevent_qwds = ['预防', '防范', '抵制', '抵御', '防止','躲避','逃避','避开','免得','逃开','避开','避掉','躲开','躲掉','绕开',\n",
    "                     '怎样才能不', '怎么才能不', '咋样才能不','咋才能不', '如何才能不',\n",
    "                     '怎样才不', '怎么才不', '咋样才不','咋才不', '如何才不',\n",
    "                     '怎样才可以不', '怎么才可以不', '咋样才可以不', '咋才可以不', '如何可以不',\n",
    "                     '怎样才可不', '怎么才可不', '咋样才可不', '咋才可不', '如何可不']\n",
    "lasttime_qwds = ['周期', '多久', '多长时间', '多少时间', '几天', '几年', '多少天', '多少小时', '几个小时', '多少年']\n",
    "cureway_qwds = ['怎么治疗', '如何医治', '怎么医治', '怎么治', '怎么医', '如何治', '医治方式', '疗法', '咋治', '怎么办', '咋办', '咋治']\n",
    "cureprob_qwds = ['多大概率能治好', '多大几率能治好', '治好希望大么', '几率', '几成', '比例', '可能性', '能治', '可治', '可以治', '可以医']\n",
    "easyget_qwds = ['易感人群', '容易感染', '易发人群', '什么人', '哪些人', '感染', '染上', '得上']\n",
    "check_qwds = ['检查', '检查项目', '查出', '检查', '测出', '试出']\n",
    "belong_qwds = ['属于什么科', '属于', '什么科', '科室']\n",
    "cure_qwds = ['治疗什么', '治啥', '治疗啥', '医治啥', '治愈啥', '主治啥', '主治什么', '有什么用', '有何用', '用处', '用途', '有什么好处', '有什么益处', '有何益处', '用来', '用来做啥', '用来作甚', '需要', '要']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "def check_words(words, question):\n",
    "    # 疑问词是否出现在提问中\n",
    "    for word in words:\n",
    "        if word in question:\n",
    "            # print(word + ' 出现在提问中')\n",
    "            return True\n",
    "    return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "# question_type = 'others'\n",
    "question_types = []\n",
    "\n",
    "# 疾病-症状\n",
    "if check_words(symptom_qwds, question) and ('disease' in types):\n",
    "    question_type = 'disease_symptom'\n",
    "    question_types.append(question_type)\n",
    "    \n",
    "# 症状-疾病\n",
    "if check_words(symptom_qwds, question) and ('symptom' in types):\n",
    "    question_type = 'symptom_disease'\n",
    "    question_types.append(question_type)\n",
    "    \n",
    "# 疾病-病因\n",
    "if check_words(cause_qwds, question) and ('disease' in types):\n",
    "    question_type = 'disease_cause'\n",
    "    question_types.append(question_type)\n",
    "\n",
    "# 疾病-并发症\n",
    "if check_words(acompany_qwds, question) and ('disease' in types):\n",
    "    question_type = 'disease_acompany'\n",
    "    question_types.append(question_type)\n",
    "\n",
    "# 疾病-可以吃/不可以吃\n",
    "if check_words(food_qwds, question) and 'disease' in types:\n",
    "    deny_status = check_words(deny_words, question)\n",
    "    if deny_status:\n",
    "        question_type = 'disease_not_food'\n",
    "    else:\n",
    "        question_type = 'disease_do_food'\n",
    "    question_types.append(question_type)\n",
    "    \n",
    "# 可以吃/不可以吃-疾病\n",
    "if check_words(food_qwds+cure_qwds, question) and 'food' in types:\n",
    "    deny_status = check_words(deny_words, question)\n",
    "    if deny_status:\n",
    "        question_type = 'food_not_disease'\n",
    "    else:\n",
    "        question_type = 'food_do_disease'\n",
    "    question_types.append(question_type)\n",
    "    \n",
    "# 疾病-药物\n",
    "if check_words(drug_qwds, question) and 'disease' in types:\n",
    "    question_type = 'disease_drug'\n",
    "    question_types.append(question_type)\n",
    "    \n",
    "# 药物-疾病\n",
    "if check_words(cure_qwds, question) and 'drug' in types:\n",
    "    question_type = 'drug_disease'\n",
    "    question_types.append(question_type)\n",
    "    \n",
    "# 疾病-检查\n",
    "if check_words(check_qwds, question) and 'disease' in types:\n",
    "    question_type = 'disease_check'\n",
    "    question_types.append(question_type)\n",
    "    \n",
    "# 检查-疾病\n",
    "if check_words(check_qwds+cure_qwds, question) and 'check' in types:\n",
    "    question_type = 'check_disease'\n",
    "    question_types.append(question_type)\n",
    "    \n",
    "#　疾病-预防措施\n",
    "if check_words(prevent_qwds, question) and 'disease' in types:\n",
    "    question_type = 'disease_prevent'\n",
    "    question_types.append(question_type)\n",
    "    \n",
    "# 疾病-疗程\n",
    "if check_words(lasttime_qwds, question) and 'disease' in types:\n",
    "    question_type = 'disease_lasttime'\n",
    "    question_types.append(question_type)\n",
    "\n",
    "# 疾病-疗法\n",
    "if check_words(cureway_qwds, question) and 'disease' in types:\n",
    "    question_type = 'disease_cureway'\n",
    "    question_types.append(question_type)\n",
    "\n",
    "# 疾病-治愈率\n",
    "if check_words(cureprob_qwds, question) and 'disease' in types:\n",
    "    question_type = 'disease_cureprob'\n",
    "    question_types.append(question_type)\n",
    "\n",
    "# 疾病-易感人群\n",
    "if check_words(easyget_qwds, question) and 'disease' in types :\n",
    "    question_type = 'disease_easyget'\n",
    "    question_types.append(question_type)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['check_disease']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "question_types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 若没有查到相关的外部查询信息，那么则将该疾病的描述信息返回\n",
    "if question_types == [] and 'disease' in types:\n",
    "    question_types = ['disease_desc']\n",
    "\n",
    "# 若没有查到相关的外部查询信息，那么则将该疾病的描述信息返回\n",
    "if question_types == [] and 'symptom' in types:\n",
    "    question_types = ['symptom_disease']\n",
    "\n",
    "# 将多个分类结果进行合并处理，组装成一个字典\n",
    "output['question_types'] = question_types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'args': {'肺气肿': ['disease'], '百日咳': ['disease'], '血常规': ['check']},\n",
       " 'question_types': ['check_disease']}"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
